package com.efesco.finance.oughtReceive;

import com.bstek.dorado.data.*;
import com.bstek.dorado.common.*;
import com.efesco.system.User;
import com.efesco.common.Tools;
import com.bstek.dorado.data.db.SqlDataset;

/**
 * manualChangePayment_manualChangeDatasetListener
 */
public class manualChangePayment_manualChangeDatasetListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
    String fesc_user_id="",sql="",foreign_enterprise_id="";
  	
  	DoradoContext context = DoradoContext.getContext();
    Object obj = context.getAttribute(context.SESSION, "User");
    if (obj != null) {
    	User user = (User) obj;
    	fesc_user_id=user.getForEmployeeId();
    	foreign_enterprise_id=user.getForeignEnterpriseId();
    	sql = "SELECT cmp.COMPANY_CHINESE_NAME,pv.PAYMENT_ID,pv.VERSION_ID,pv.AMOUNT_MONTH," +
				"pcc.COMMIT_TIME,pv.PAYMENT_VERSION_ID,pv.SINGLE_COMPANY_ID,pcc.CHG_COMMIT_ID," +
				"pv.PAYMENT_VERSION_ID paymentVersionId,1 paymentType " +
				"FROM " +  
				"s_payment_chg_commit pcc,s_payment_version pv,s_single_company cmp," +
				"s_company_businessman cbm,s_fe_emp_businesstype busi,s_fe_emp_scope scp " + 
				"WHERE "+ 
				"pcc.PAYMENT_VERSION_ID = pv.PAYMENT_VERSION_ID AND " + 
				"pv.SINGLE_COMPANY_ID = cmp.SINGLE_COMPANY_ID AND " +
				"cmp.single_company_id=cbm.single_company_id and " + 
				"cbm.businessman_id=scp.fe_empid2 and cbm.business_id=busi.business_type_id " + 
				"and busi.employee_id=scp.fe_empid1 and cbm.start_date<=sysdate " + 
				"and (cbm.end_date is null or cbm.end_date>=sysdate) and " + 
				"scp.fe_empid1=" + fesc_user_id + " and cmp.FOREIGN_ENTERPRISE_ID = " + foreign_enterprise_id  +
				" and pcc.CHG_FLAG = 4 and pcc.FLAG = '1' and cbm.business_id=1 " ;
    	if (!Tools.toStr(dataset.parameters().getString("singleCompanyId")).equals("")
    		&& !Tools.toStr(dataset.parameters().getString("singleCompanyId")).equals("null")	)  {
    		sql = sql + " and cmp.single_company_id = " + dataset.parameters().getString("singleCompanyId");
    	}
    	
    	SqlDataset sqlDataset=(SqlDataset)dataset;
    	sqlDataset.setSql(sql);
    }
  	
    return true;
  }

}
